package abd.pr1.Interface;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;

import abd.pr1.Models.Actor;
import abd.pr1.Models.Personaje;

public class AdminActoresPanel extends JPanel {
private static final long serialVersionUID = 1L;
	
	private JList<Actor> listaActores;
	private JButton info;
	private JButton nueva;
	private JButton buscarButton;
	private JTextField buscarTexto;
	public AdminActoresPanel(){
		super();
		this.build();
		
	}

	private void build() {
		
		this.setLayout(new BorderLayout());
		
		JPanel buscarContainer = new JPanel(new BorderLayout());
		JLabel buscarActor = new JLabel("Buscar actor");
		buscarTexto = new JTextField();
	    buscarButton= new JButton("Buscar");
		buscarButton.setActionCommand("buscar_admin_actor");
		buscarContainer.add(buscarActor,BorderLayout.WEST);
		buscarContainer.add(buscarTexto,BorderLayout.CENTER);
		buscarContainer.add(buscarButton,BorderLayout.EAST);
		
		this.add(buscarContainer,BorderLayout.NORTH);
				
		listaActores = new JList<Actor>();
		
		this.add(listaActores, BorderLayout.CENTER);
		
		JPanel botonesContainer = new JPanel();
	    info= new JButton("Ver informacion");
	    info.setActionCommand("info_admin_actor");
	    
	    nueva= new JButton("Nuevo actor");
	    nueva.setActionCommand("nuevo_actor");
	    
	    botonesContainer.add(info);
	    botonesContainer.add(nueva);
	    
		this.add(botonesContainer, BorderLayout.SOUTH);

	}
	public String getBuscarTexto(){
		return this.buscarTexto.getText();
	}
	public void addListener(ActionListener a){
		info.addActionListener(a);
		nueva.addActionListener(a);
		buscarButton.addActionListener(a);
	}
	public void setListaActores(List<Actor> actores){
		
		listaActores.setListData(actores.toArray(new Actor[actores.size()]));
	}
	public Actor getSelectedActor(){
		return listaActores.getSelectedValue();
	}
}
